/**
 * 组合式函数我们也称为自定义hook，它的主要的目的为了复用逻辑代码
 * 我们总是喜欢以use开头来定义这个函数
 */
import {reactive,onMounted,onBeforeUnmount} from 'vue'

interface PointType{
    x:number,
    y:number
}
const usePoint=()=>{
    let point=reactive<PointType>({
        x:0,
        y:0
    })
    const setPoint=(e:MouseEvent)=>{
        point.x=e.clientX
        point.y=e.clientY
    }
    onMounted(()=>{
        window.addEventListener('mousemove',setPoint)
    })
    onBeforeUnmount(()=>{
        window.removeEventListener('mousemove',setPoint)
    })
    return point

}
export default usePoint